package com.ztf.shopping.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ztf.shopping.service.UserService;
import com.ztf.shopping.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 增加订单的数量
 */
@WebServlet("/addCount")
public class AddCount extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String count = request.getParameter("count");
        String id = request.getParameter("id");
        Object user = request.getSession().getAttribute("loginUser");
        UserService userService = new UserServiceImp();
        Map<String,String> msg = userService.addShopCount(user, id, count);

        ObjectMapper om = new ObjectMapper();
        om.writeValue(response.getOutputStream(),msg);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
